package com.nine.demo.service.impl;

import com.nine.demo.factory.SmsHandleFactory;
import com.nine.demo.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
public class AliCloudSmsServiceImpl implements SmsService, InitializingBean {

    @Autowired
    private SmsHandleFactory smsHandleFactory;

    static final String ALI = "ali";

    /**
     * 发送短信
     *
     * @param phoneNumber
     * @param templateCode
     * @param templateParam
     */
    @Override
    public void sendSms(String phoneNumber, String templateCode, String templateParam) {
        log.info("阿里云短信服务。。。。");
        log.info("手机号：{}", phoneNumber);
        log.info("模板编码：{}", templateCode);
        log.info("模板参数：{}", templateParam);
    }

    /**
     * 初始化时，给 map 中添加当前的实例
     *
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        smsHandleFactory.handlerMap.put(ALI, this);
    }
}
